package com.itaming.lycheeframework.support.utils;

import lombok.experimental.UtilityClass;

/**
 * Character工具类
 *
 * @author A.Ming
 */
@UtilityClass
public class CharacterUtil {

    /**
     * 判断是否为 {@code ASCII} 字符
     *
     * @param c 字符
     * @return boolean
     */
    public static boolean isAscii(char c) {
        return c < 128;
    }

    /**
     * 判断是否为 {@code ASCII} 可显示字符
     *
     * @param c 字符
     * @return boolean
     */
    public static boolean isAsciiPrintable(char c) {
        return c >= 32 && c < 127;
    }

    /**
     * 判断是否为 {@code ASCII} 控制字符
     *
     * @param c 字符
     * @return boolean
     */
    public static boolean isAsciiControl(char c) {
        return c < 32 || c == 127;
    }

    /**
     * 判断是否为 {@code ASCII} 字母
     *
     * @param c 字符
     * @return boolean
     */
    public static boolean isAsciiAlpha(char c) {
        return isAsciiAlphaLower(c) || isAsciiAlphaUpper(c);
    }

    /**
     * 判断是否为 {@code ASCII} 小写字母
     *
     * @param c 字符
     * @return boolean
     */
    public static boolean isAsciiAlphaLower(char c) {
        return c >= 'a' && c <= 'z';
    }

    /**
     * 判断是否为 {@code ASCII} 大写字母
     *
     * @param c 字符
     * @return boolean
     */
    public static boolean isAsciiAlphaUpper(char c) {
        return c >= 'A' && c <= 'Z';
    }

    /**
     * 判断是否为 {@code ASCII} 数字
     *
     * @param c 字符
     * @return boolean
     */
    public static boolean isAsciiNumeric(char c) {
        return c >= '0' && c <= '9';
    }

    /**
     * 判断是否为 {@code ASCII} 字母或数字
     *
     * @param c 字符
     * @return boolean
     */
    public static boolean isAsciiAlphaNumeric(char c) {
        return isAsciiAlpha(c) || isAsciiNumeric(c);
    }

    /**
     * 比较两个字符
     *
     * @param c1 字符1
     * @param c2 字符2
     * @return 相等返回 {@code 0}，{@code c1} 大于 {@code c2} 时返回正数，{@code c1} 小于 {@code c2} 时返回负数
     */
    public static int compare(char c1, char c2) {
        return c1 - c2;
    }

    /**
     * 判断是否为空白符
     *
     * @param c 字符
     * @return boolean
     */
    public static boolean isWhitespace(char c) {
        return Character.isWhitespace(c);
    }

    /**
     * 判断是否为数字
     *
     * @param c 字符
     * @return boolean
     */
    public static boolean isDigit(char c) {
        return Character.isDigit(c);
    }

    /**
     * 判断是否为数字或空格
     *
     * @param c 字符
     * @return boolean
     */
    public static Boolean isDigitSpace(Character c) {
        return Character.isDigit(c) || Character.isSpaceChar(c);
    }

    /**
     * 判断是否为字母
     *
     * @param c 字符
     * @return boolean
     */
    public static boolean isLetter(char c) {
        return Character.isLetter(c);
    }

    /**
     * 判断是否由字母或空格
     *
     * @param c 字符
     * @return boolean
     */
    public static boolean isLetterSpace(char c) {
        return Character.isLetter(c) || Character.isSpaceChar(c);
    }

    /**
     * 判断是否为字母或数字
     *
     * @param c 字符
     * @return boolean
     */
    public static boolean isAlphaNumber(char c) {
        return Character.isLetterOrDigit(c);
    }

    /**
     * 判断是否为字母、数字或空格
     *
     * @param c 字符
     * @return boolean
     */
    public static boolean isAlphaNumberSpace(char c) {
        return Character.isLetterOrDigit(c) || Character.isSpaceChar(c);
    }

}
